﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DaInterFace;
using DaInterFace.PDA;
using DaInterFace.PDA.P02;

namespace P02
{
    /// <summary>
    /// A10 新增采样单
    /// </summary>
    public class A10 : IPDAChild
    {
        public void Code(IPDA handler, CodeResult CR, PDACodeUser user, String parameter)
        {
            P02A10P P = (P02A10P)handler.SerialApi.Deserialize(typeof(P02A10P), parameter, CR.SerialType);
            try
            {
                SqlParameter[] sps = new SqlParameter[2];
                sps[0] = new SqlParameter("@OrderID", SqlDbType.NVarChar, 50);
                sps[0].Value = P.OrderID;
                sps[1] = new SqlParameter("@User", SqlDbType.NVarChar, 50);
                sps[1].Value = user.UserName;

                Recordset rs = handler.Data.ExeProcedure(P.BaseNo, "EXEC KEW_SAMP_NEW @OrderID,@User", sps);

                if (rs.Enable)
                {
                    if (rs.Data.Tables[0].Rows[0][0].ToString() == "TRUE")
                    {
                        CR.Result = EnumResult.Normal;
                        CR.Message = String.Format("操作员{0}对账套{1}中的订单{2}新增了采样单{3}", user.UserName, P.BaseNo, P.OrderID, rs.Data.Tables[0].Rows[0][2].ToString());
                    }
                    else
                    {
                        CR.Result = EnumResult.Error;
                        CR.Message = "新增采样单出现错误：" + rs.Data.Tables[0].Rows[0][1].ToString();
                    }
                }
                else
                {
                    CR.Result = EnumResult.Error;
                    CR.Message = "数据库错误";
                }
            }
            catch (Exception ex)
            {
                CR.Result = EnumResult.Error;
                CR.Message = String.Format("发生错误:{0}", ex.Message);
            }
        }
    }


}
